package com.Portal.controller;

import com.Portal.pojo.GoodVo;
import com.Portal.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;

/**
 * 搜索
 */
@Controller
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;
    /**
     * 跳转到搜锁业
     * @param keywords
     * @param model
     * @return
     */
    @RequestMapping("index")
    public String index(String keywords, Model model){
        model.addAttribute("searchStr",keywords);
        return "search/doSearch";
    }

    @RequestMapping("searchGoods")
    @ResponseBody
    public List<GoodVo> searchGoods(String keywords, Integer pageNum, Integer pageSize) throws IOException {
        return searchService.GoodsList(keywords,pageNum,pageSize);

    }
}
